NAME = ur

LIBPCAP_DIR = $(shell ls | grep 'libpcap')
INCLUDE = -I$(LIBPCAP_DIR) -I$(LIBPCAP_DIR)/pcap
LIBS = $(LIBPCAP_DIR)/libpcap.a
SHELL_CMD = grep "^LIBS" $(LIBPCAP_DIR)/Makefile | awk -F'=' '{print $$2}'
MACHINE_TYPE = $(shell uname -m)
HOST = $(MACHINE_TYPE)-pc-linux-gnu
GCC = g++

all: ur

libpcap.a:
	test -f $(LIBPCAP_DIR)/Makefile || (cd $(LIBPCAP_DIR); chmod +x configure; chmod +x *.sh; ./configure --host=$(HOST))
	make -C $(LIBPCAP_DIR) libpcap.a
	@echo "<Tips> Build 'libpcap.a' success!"
	@echo

ur: libpcap.a
	$(GCC) -o $(NAME) ur.cpp $(INCLUDE) $(LIBS) `$(SHELL_CMD)`
	@echo "<Tips> Build 'ur' success!"
	@echo

clean:
	make -C $(LIBPCAP_DIR) clean
	rm -f $(LIBPCAP_DIR)/Makefile
	rm -f $(NAME)
